package cn.edu.mju.property.service.impl;

import cn.edu.mju.property.dao.BuildingDao;
import cn.edu.mju.property.dao.UnitDao;
import cn.edu.mju.property.dao.impl.BuildingDaoImpl;
import cn.edu.mju.property.dao.impl.UnitDaoImpl;
import cn.edu.mju.property.entity.Building;
import cn.edu.mju.property.entity.PageBean;
import cn.edu.mju.property.entity.Unit;
import cn.edu.mju.property.service.BuildingService;
import cn.edu.mju.property.service.UnitService;

import java.util.List;

/**
 * @author HUI
 */
public class BuildingServiceImpl implements BuildingService {

    private BuildingDao dao = new BuildingDaoImpl();


    @Override
    public boolean addBuilding(Building building) {
        return false;
    }

    @Override
    public boolean delBuilding(int id) {
        return false;
    }

    @Override
    public boolean updateBuilding(Building building) {
        return false;
    }

    @Override
    public PageBean<Building> findBuildingByPage(String _currentPage, String _rows) {
        int currentPage = Integer.parseInt(_currentPage) ;
        int rows = Integer.parseInt(_rows) ;

        PageBean<Building> pb = new PageBean<Building>();
        pb.setCurrentPage(currentPage);
        pb.setRows(rows);

        //总记录数
        int totalCount = dao.findTotalCount();
        pb.setTotalCount(totalCount);

        //开始值
        int start = (currentPage - 1) * rows;
        List<Building> list = dao.findBuildingByPage(start,rows);
        pb.setList(list);

        int totalPage = totalCount % rows == 0 ? (totalCount/rows) : (totalCount/rows) + 1;
        pb.setTotalPage(totalPage);

        return pb;
    }
}
